﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Util;
using Model;
public partial class admin_adminManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Util.UtilWeb.CheckRights(this);
            LoadView();
        }
    }

    private void LoadView()
    {
        ((Label)Master.FindControl("lblTitle")).Text = "用户管理";

        tb_admin obj = new BllAdmin().GetSingle(c => c.username == UtilWeb.GetCookie(this, KoInfo.CookieAdmin));
        this.txtUsername.Text = obj.username;

        this.hdId.Value = obj.id.ToString();
        this.res.Value = "恢复";

    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {

        string name = this.txtUsername.Text;
        string pwd = this.txtPwd.Text;
        string repwd = this.txtRepwd.Text;
        if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(pwd) || string.IsNullOrWhiteSpace(repwd))
        {
            UtilWeb.Message(this, KoInfo.FillBlank, null);
        }
        else if (pwd != repwd)
        {
            UtilWeb.Message(this, "两次密码不一样！", null);
        }
        else
        {
            BllAdmin bll = new BllAdmin(this);

            tb_admin obj = bll.GetSingle(int.Parse(this.hdId.Value));

            obj.pwd = pwd;
            if (bll.Update(obj))
            {
                UtilWeb.Message(this, Util.KoInfo.OperateSuccess, null);
            }
            else { Util.UtilWeb.Message(this, Util.KoInfo.OperateFailure, null); }

        }
    }

}